package com.example.cardgame

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.cardgame.databinding.ActivityCardGameBinding
import com.example.cardgame.fragments.PersonalInfoFragment
import com.example.cardgame.fragments.ThreeCardGameFragment
import com.example.cardgame.fragments.TwoCardGameFragment
import com.google.android.material.navigation.NavigationBarView


class CardGameActivity : AppCompatActivity() {
    private val binding by lazy {ActivityCardGameBinding.inflate(layoutInflater) }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(binding.root)

        binding.navView.setOnItemSelectedListener(NavigationBarView.OnItemSelectedListener{
            item -> when (item.itemId) {
                R.id.navigation_personal_info -> {
                    loadFragment(PersonalInfoFragment())
                    return@OnItemSelectedListener true
                }
                R.id.navigation_two_card_game -> {
                    loadFragment(TwoCardGameFragment())
                    return@OnItemSelectedListener true
                }
                R.id.navigation_three_card_game -> {
                    loadFragment(ThreeCardGameFragment())
                    return@OnItemSelectedListener true
                }
        }
            false
        })
        // 默认加载PersonalInfoFragment
        if (savedInstanceState == null) {
            binding.navView.selectedItemId = R.id.navigation_personal_info
        }

    }
    private fun loadFragment(fragment: Fragment) {
        supportFragmentManager.beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .commit()
    }
}